package com.yogee.topseller.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.bean.ExpressDetailBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 快递详情里内容list的适配器
 *
 * @author hanyu
 *         created by 2017/7/12 11:21
 */

public class ExpressDetailAdapter extends RecyclerView.Adapter<ExpressDetailAdapter.ExpressContentViewHolder> {

    private Context mContext;//上下文
    private List<ExpressDetailBean.Express> mDisMessage = new ArrayList<>();

    public ExpressDetailAdapter(Context context) {
        this.mContext = context;
    }

    /**
     * 添加信息
     */
    public void addData(List<ExpressDetailBean.Express> disMessage) {
        this.mDisMessage = disMessage;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(ExpressContentViewHolder holder, final int position) {
        holder.tvState.setText(mDisMessage.get(position).getCenter());//设置物流信息
        holder.tvTime.setText(mDisMessage.get(position).getTime());//设置时间
        if (position == 0) {
            holder.leftIcon.setImageResource(R.drawable.corens_100_style);
            holder.tvState.setTextColor(Color.parseColor("#eb5256"));
            holder.tvTime.setTextColor(Color.parseColor("#eb5256"));
            holder.top.setVisibility(View.INVISIBLE);//一条上线不显示
            holder.bottom.setVisibility(View.VISIBLE);//一条下线显示
        } else {
            holder.leftIcon.setImageResource(R.drawable.corens_100_gary);
            holder.tvState.setTextColor(mContext.getResources().getColor(R.color.hint_color1));
            holder.tvTime.setTextColor(mContext.getResources().getColor(R.color.hint_color1));
            holder.top.setVisibility(View.VISIBLE);
            holder.bottom.setVisibility(View.VISIBLE);
        }
        if (position == mDisMessage.size() - 1) {
            holder.top.setVisibility(View.VISIBLE);//最后一条上线显示
            holder.bottom.setVisibility(View.INVISIBLE);//最后一条下线不显示
        }
    }

    @Override
    public ExpressContentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View contentView = LayoutInflater.from(mContext).inflate(R.layout.item_express_detail, null);
        return new ExpressContentViewHolder(contentView);
    }

    @Override
    public int getItemCount() {
        return null == mDisMessage ? 0 : mDisMessage.size();
    }

    class ExpressContentViewHolder extends RecyclerView.ViewHolder {

        ImageView leftIcon;
        TextView tvState, tvTime;
        LinearLayout layout;
        View top, bottom;

        public ExpressContentViewHolder(View view) {
            super(view);
            layout = (LinearLayout) view.findViewById(R.id.layout_express);
            leftIcon = (ImageView) view.findViewById(R.id.iv_icon);
            tvState = (TextView) view.findViewById(R.id.tv_state);
            tvTime = (TextView) view.findViewById(R.id.tv_time);
            top = view.findViewById(R.id.tv_top);
            bottom = view.findViewById(R.id.tv_bottom);
        }
    }

}
